package com.qidian.zl.paper.factory;

import com.qidian.zl.paper.service.*;
import com.qidian.zl.paper.service.impl.*;

import java.util.HashMap;
import java.util.Map;

public class ServiceFactory {
    private static Map serviceObjs=new HashMap<>();
    public static PaperService getPaperService(){
        if (serviceObjs.containsKey("PaperService")){
            return (PaperService) serviceObjs.get("PaperService");
        }else {
            PaperService paperService=new PaperServiceImpl();
            serviceObjs.put("paperService",paperService);
            return paperService;
        }
    }
    public static FieldService getFieldService(){
        if (serviceObjs.containsKey("PaperService")){
            return (FieldService) serviceObjs.get("fieldService");
        }else {
            FieldService fieldService=new FieldServiceImpl();
            serviceObjs.put("fieldService",fieldService);
            return fieldService;
        }
    }
   public static SelectorService getSelectorSerice(){
        if (serviceObjs.containsKey("selectorService")){
            return (SelectorService)serviceObjs.get("selectorService");
        }else {
            SelectorService selectorService=new SelectorServiceImpl();
            serviceObjs.put("selectorService",selectorService);
            return selectorService;
        }
   }

    public static AnswerService getAnswerService(){
        if(serviceObjs.containsKey("answerService")){
            return (AnswerService) serviceObjs.get("answerService");
        }
        AnswerService answerService = new AnswerServiceImpl();
        serviceObjs.put("answerService",answerService);
        return answerService;
    }
    public static AdminService getAdminService(){
        if (serviceObjs.containsKey("userService")){
            return (AdminService) serviceObjs.get("userService");
        }else {
            AdminService adminService =new AdminServiceImpl();
            serviceObjs.put("userService", adminService);
            return adminService;
        }
    }


}
